<template>
	<view class="socverifycode" v-if="showPage" :style="'padding-bottom:'+ pageSafeArea +'rpx;'">
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">活动名称</view>
			<view class="ml-10 ellipsis">{{info.huodong_name}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">用户姓名</view>
			<view class="ml-10">{{info.name}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">用户电话</view>
			<view class="ml-10">{{info.mobile}}</view>
		</view>
		<block v-if="huodong_id==160">
			<view class="groupmanage_input_box box_bg">
				<view class="mr-5 label">随行人员</view>
				<view v-if="info.sign_status==0" class="ml-10">
					<uni-section type="line" padding>
						<uni-number-box :min="1" :max="6" v-model="info.man_num" />
					</uni-section>
				</view>
				<view v-if="info.sign_status==1" class="ml-10">{{info.man_num}}</view>
			</view>
			<view class="groupmanage_input_box box_bg">
				<view class="mr-5 label">是否有车</view>
				<view class="ml-10">{{info.is_have_car==1?'是':'否'}}</view>
			</view>
			<block v-if="info.is_have_car==1">
				<view v-if="info.car_number" class="groupmanage_input_box box_bg">
					<view class="mr-5 label">车牌号</view>
					<view class="ml-10">{{info.car_number}}</view>
				</view>
				<view class="groupmanage_input_box box_bg">
					<view class="mr-5 label">是否斯巴鲁车主</view>
					<view class="ml-10">{{info.is_subaru==1?'是':'否'}}</view>
				</view>
				<view class="groupmanage_input_box box_bg" v-if="info.is_subaru==1">
					<view class="mr-5 label">车型</view>
					<view class="ml-10">{{info.car_series}}</view>
				</view>
				<view class="groupmanage_input_box box_bg" v-if="info.is_subaru==0">
					<view class="mr-5 label">品牌</view>
					<view class="ml-10">{{info.car_brand}}</view>
				</view>
				<view class="groupmanage_input_box box_bg" style="height: auto;">
					<view style="width: 100%;padding: 30rpx 0;">
						<view class="mr-5 label">活动环节</view>
						<view class="projects_cell" v-for="(item,index) in info.project_pay_type_arr" :key="item.id">
							<view class="flex-1">{{item.name}}</view>
							<block v-if="item.id!=1">
								<view v-if="item.sign_status==0" class="projects_btn"
									@click="submitZHProject(item.id,item.name)">确认完成</view>
								<view v-if="item.sign_status==1" class="projects_btn_def">已完成</view>
							</block>
						</view>
					</view>
				</view>
				<view class="groupmanage_input_box box_bg">
					<view class="mr-5 label">赛道巡游乘客</view>
					<view class="ml-10">
						<span v-for="(item,index) in info.project_pay_man_card" :key="item.id">{{item.name}}
							<block v-if="index<info.project_pay_man_card.length-1">、</block>
						</span>
					</view>
				</view>
				<view class="groupmanage_input_box box_bg" style="height: auto;">
					<view style="width: 100%;padding: 30rpx 0;">
						<view class="mr-5 f-14">行驶证照片</view>
						<view class="travel_img_box">
							<image v-if="info.driving_license_pic" class="travel_img"
								:src="picUrl+info.driving_license_pic" mode="aspectFill"></image>
						</view>
					</view>
				</view>
				<view class="groupmanage_input_box box_bg" style="height: auto;">
					<view style="width: 100%;padding: 30rpx 0;">
						<view class="mr-5 f-14">爱车照片</view>
						<view class="travel_img_box">
							<image v-if="info.pic" class="travel_img" :src="picUrl+info.pic" mode="aspectFill"></image>
						</view>
					</view>
				</view>
			</block>
		</block>
		<block v-else>
			<view v-if="info.car_series!='无车'" class="groupmanage_input_box box_bg" style="height: auto;">
				<view style="width: 100%;padding: 30rpx 0;">
					<view class="mr-5 f-14">爱车照片</view>
					<view class="travel_img_box">
						<image v-if="info.pic" class="travel_img" :src="picUrl+info.pic" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</block>
		<view class="bottom_block_fixed" :style="'padding-bottom:'+ bottomSafeArea+'rpx;'">
			<view v-if="info.sign_status==0" class="next_step_btn" @click="submitInto">确认入场</view>
			<view v-else class="next_step_btn_def">已入场</view>
			<view v-if="info.experience_pay_status==1&&info.experience_sign_status==0" class="next_step_btn"
				@click="submitIntoTy">发放体验卷</view>
			<view v-if="info.experience_sign_status==1" class="next_step_btn_def">已发放体验卷</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserApplyActiveInfo,
		socVerifyCode,
		socVerifyCodeTy,
		submitZHProject
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				huodong_id: '',
				user_id: 0,
				huodong_join_group_id: 0,
				info: '',
				user: {
					wx_avatar: '',
					username: ''
				},
				isSubmit: true,
				showPage: false,
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				safeBottom: uni.getSystemInfoSync().safeAreaInsets.bottom > 0 ? true : false,
				pageSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom + 350 : 350,
				bottomSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom : 15
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
			if (uni.getStorageSync('onload')) {
				this.getUserApplyActiveInfo()
				uni.removeStorage({
					key: 'onload'
				})
			}
		},
		onLoad(options) {
			console.log(options)
			var scene = decodeURIComponent(options.scene)
			var list = scene.split('_');
			console.log(list)
			this.huodong_id = list[0]
			this.user_id = list[1] ? list[1] : 0
			this.huodong_join_group_id = list[2] ? list[2] : 0
			if (uni.getStorageSync('access_token')) {
				this.getUserApplyActiveInfo()
			}
			var params = {
				event_code: '经销商核销',
				path: 'pages/groupmanage/socverifycode',
				event_id: this.huodong_id,
				title: '',
				source_page: '打开页面',
				value: '',
			}
			app.BurialPoint(params)
		},
		methods: {
			getUserApplyActiveInfo() {
				getUserApplyActiveInfo({
					huodong_id: this.huodong_id,
					user_id: this.user_id,
					huodong_join_group_id: this.huodong_join_group_id
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
						this.showPage = true
						var params = {
							event_code: '经销商核销',
							path: 'pages/groupmanage/socverifycode',
							event_id: this.huodong_id,
							title: '',
							source_page: '经销商核销-详情接口',
							value: '',
						}
						app.BurialPoint(params)
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 2000
						})
						// setTimeout(function() {
						// 	uni.reLaunch({
						// 		url: '/pages/start/start'
						// 	})
						// }, 2100)
					}
				})
			},
			submitZHProject(project_id, name) {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					uni.showModal({
						content: '确认完成吗？',
						confirmColor: '#00A0DC',
						confirmText: "确认",
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								submitZHProject({
									id: that.info.id,
									project_id: project_id
								}).then(res => {
									if (res.state == 1) {
										that.getUserApplyActiveInfo()
										that.isSubmit = true
										uni.showToast({
											title: '成功',
											mask: true,
											icon: 'success',
											duration: 1500
										})
										var params = {
											event_code: '经销商核销',
											path: 'pages/groupmanage/socverifycode',
											event_id: that.huodong_id,
											title: '',
											source_page: '经销商核销-' + name + '确认完成',
											value: '',
										}
										app.BurialPoint(params)
									} else {
										uni.showToast({
											title: res.error[0],
											mask: true,
											icon: 'none',
											duration: 1500
										})
									}
								})

							} else if (res.cancel) {
								console.log('用户点击取消');
								that.isSubmit = true
							}
						}
					});
				}
			},
			submitInto() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					uni.showModal({
						content: '确认入场吗？',
						confirmColor: '#00A0DC',
						confirmText: "确认",
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								socVerifyCode({
									id: that.info.id,
									man_num: that.info.man_num,
									huodong_join_group_id: that.info.huodong_join_group_id
								}).then(res => {
									if (res.state == 1) {
										that.getUserApplyActiveInfo()
										that.isSubmit = true
										uni.showToast({
											title: '成功',
											mask: true,
											icon: 'success',
											duration: 1500
										})
										var params = {
											event_code: '经销商核销',
											path: 'pages/groupmanage/socverifycode',
											event_id: that.huodong_id,
											title: '',
											source_page: '经销商核销-确认入场',
											value: '',
										}
										app.BurialPoint(params)
									} else {
										uni.showToast({
											title: res.error[0],
											mask: true,
											icon: 'none',
											duration: 1500
										})
									}
								})

							} else if (res.cancel) {
								console.log('用户点击取消');
								that.isSubmit = true
							}
						}
					});
				}
			},
			submitIntoTy() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					uni.showModal({
						content: '确认发放吗？',
						confirmColor: '#00A0DC',
						confirmText: "确认",
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								socVerifyCodeTy({
									id: that.info.id,
									huodong_join_group_id: that.info.huodong_join_group_id
								}).then(res => {
									if (res.state == 1) {
										that.getUserApplyActiveInfo()
										that.isSubmit = true
										uni.showToast({
											title: '成功',
											mask: true,
											icon: 'success',
											duration: 1500
										})
										var params = {
											event_code: '经销商核销',
											path: 'pages/groupmanage/socverifycode',
											event_id: that.huodong_id,
											title: '',
											source_page: '经销商核销-确认发放体验卷',
											value: '',
										}
										app.BurialPoint(params)
									} else {
										uni.showToast({
											title: res.error[0],
											mask: true,
											icon: 'none',
											duration: 1500
										})
									}
								})

							} else if (res.cancel) {
								console.log('用户点击取消');
								that.isSubmit = true
							}
						}
					});
				}
			}
		},
	}
</script>

<style lang="scss">
	.socverifycode {
		padding: 30rpx 70rpx;

		.groupmanage_input_box {
			min-height: 80rpx;
			font-size: 26rpx;
			margin-top: 20rpx;
			padding: 0 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-radius: 4px;
			background-color: #F7F7F7;
			border: 2rpx solid #F7F7F7;

			.label {
				color: #999;
				font-size: 26rpx;
			}
		}

		.projects_cell {
			margin-top: 40rpx;
			display: flex;
			align-items: center;
		}

		.projects_cell:first-child {
			margin-top: 20rpx;
		}

		.projects_btn {
			min-width: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			font-size: 24rpx;
			padding: 5rpx 10rpx;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.projects_btn_def {
			min-width: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			font-size: 24rpx;
			padding: 5rpx 10rpx;
			border-radius: 8rpx;
			background-color: #949494;
		}

		.travel_img_box {
			width: 100%;
			height: 45vw;
			text-align: center;
			margin-top: 20rpx;
			border-radius: 8rpx;

			.travel_img {
				width: 100%;
				height: 45vw;
				border-radius: 8rpx;
			}
		}

		.next_step_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 60rpx 0;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.next_step_btn_def {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 40rpx 0;
			border-radius: 8rpx;
			background-color: #E9E9E9;
		}

		.bottom_block_fixed {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 1;
			padding-left: 30rpx;
			padding-right: 30rpx;
			background-color: #ffffff;
		}
	}
</style>